<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">

    /**
    * @param {number} capacity
    */
    var LRUCache = function(capacity) {
        this.capacity=capacity;
        this.map=new Map();
    };

    /** 
    * @param {number} key
    * @return {number}
    */
    LRUCache.prototype.get = function(key) {
        var x=this.map.get(key);
        if(x==undefined)
        {
            return -1;
        }
        this.map.delete(key);
        this.map.set(key,x);
        return x;
    };

    /** 
    * @param {number} key 
    * @param {number} value
    * @return {void}
    */
    LRUCache.prototype.put = function(key, value) {
        if(this.map.has(key))
        {
            this.map.delete(key);
        }
        this.map.set(key,value);
        var keys=this.map.keys();
        if(this.capacity<this.map.size)
        {
            this.map.delete(keys.next().value);
        }
    };

    /**
    * Your LRUCache object will be instantiated and called as such:
    * var obj = new LRUCache(capacity)
    * var param_1 = obj.get(key)
    * obj.put(key,value)
    */
    </script>
</body>
</html>